package com.chunyu.app.utils;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;

public class YzqHttpUrlClient {
	MyHttpUrlClient httpClient = new MyHttpUrlClient();
	public static final String baseUrl = "http://113.207.76.249:6006/yzqweb";
	public static final String FileBasePath = "E:/test/";

	public static enum UrlKey {
		auth_captchaKey, auth_doLogin, upload_ysxx, upload_doctor,upload_yskq,upload_device,upload_hmxs,upload_xscf
	}

	public static final Map<UrlKey, String> urlMapping = new HashMap<UrlKey, String>();

	static {
		urlMapping.put(UrlKey.auth_captchaKey, baseUrl + "/auth/captchaKey.do");
		urlMapping.put(UrlKey.auth_doLogin, baseUrl + "/auth/doLogin.do");
		urlMapping.put(UrlKey.upload_ysxx, baseUrl + "/jgxt/ypjyjxc/cyryysxxinfo/doUpload.do");
		urlMapping.put(UrlKey.upload_doctor, baseUrl + "/jgxt/ypjyjxc/ypjydoctorinfo/doUpload.do");
		urlMapping.put(UrlKey.upload_yskq, baseUrl + "/jgxt/ypjyjxc/ypjyyskqxxinfo/doUpload.do");
		urlMapping.put(UrlKey.upload_device, baseUrl + "/jgxt/ypjyjxc/ypjyrxdeviceinfo/doUpload.do");
		urlMapping.put(UrlKey.upload_hmxs, baseUrl + "/jgxt/ypjyjxc/ypjyhmxsinfo/doUpload.do");
		urlMapping.put(UrlKey.upload_xscf, baseUrl + "/jgxt/ypjyjxc/ypjyxscfinfo/doUpload.do");
	}

	public String captchaKey() {
		Map<String, Object> params = new HashMap<String, Object>();
		return this.httpClient.post(urlMapping.get(UrlKey.auth_captchaKey), params);
	}

	public void prpareOrgInfo(Map<String, Object> params) {
		// params.put("chainSid", "cyAdmin");
		// params.put("chainCode", "remotesfxx");
		// params.put("chainName", "remotesfxx");
		params.put("otherOrgSid", "900000000000007");//平台标识
		params.put("otherOrgName", "重庆医康小燕网络科技有限公司");//平台名称
		params.put("organizationSid", "200201200000247");//药店标识
		params.put("organizationName", "重庆市万家燕大药房连锁有限公司渝中区肖家湾店");//药店名称

	}

	/**
	 * 药师
	 * @return
	 */
	public String doUploadYsxx() {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("province", "");
		params.put("name", "cyAdmin");
		params.put("sex", "男");
		params.put("nation", "cyAdmin");
		params.put("education", "cyAdmin");
		params.put(" major", "cyAdmin");
		params.put("positionalTitle", "cyAdmin");
		params.put("photoFile", JSONFile.loadFiles(FileBasePath, "mirana.zip", "photo-2.jpg", "photo-3.jpg"));
		params.put("idCode", "cyAdmin");
		params.put("idFile", JSONFile.loadFiles(FileBasePath, "id-1.jpg", "id-2.jpg"));
		params.put("pecCode", "cyAdmin");
		params.put("pecFile", JSONFile.loadFiles(FileBasePath, "pec-1.jpg"));
		params.put("gainedYear", "2012");
		params.put("graduatedFrom", "cyAdmin");
		params.put("practiceArea", "cyAdmin");
		params.put("typeOfJob", "cyAdmin");
		params.put("nbzzbm", "cyAdmin");
		params.put("address", "cyAdmin");
		params.put("orgTel", "cyAdmin");
		params.put("post", "cyAdmin");
		params.put("tel", "cyAdmin");
		params.put("remark", "cyAdmin");
		params.put("userStatus", 1);

		prpareOrgInfo(params);
		return this.httpClient.postJSON(urlMapping.get(UrlKey.upload_ysxx), params);
	}

	/**
	 * 药师考勤
	 * @return
	 */
	public String doYskq() {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("nbzzbm", "1111111111111");
		params.put("name", "张三");
		params.put("idCode", "500224199310149091");
		params.put("attendDt", "2018-10-01");
		params.put("loginTime", "2018-10-01 08:00:00");
		params.put("loginoutTime", "2018-10-01 13:00:20");

		prpareOrgInfo(params);
		return this.httpClient.postJSON(urlMapping.get(UrlKey.upload_yskq), params);
	}
	
	/**
	 * 喊麻碱销售
	 * @return
	 */
	public String doHmjxs() {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("nbzzbm", "1111111111111");
		params.put("djbh", "987654321");
		params.put("xsrq", "2018-10-01 08:00:00");
		params.put("custName", "李四");
		params.put("custIdCode", "50022419221014889");
		
		params.put("ysmc", "cyAdmin");
		params.put("ypbm", "yp007");
		params.put("yptymc", "999感冒林");
		params.put("qty", 2);

		prpareOrgInfo(params);
		return this.httpClient.postJSON(urlMapping.get(UrlKey.upload_hmxs), params);
	}
	
	/**
	 * 销售处方
	 * @return
	 */
	public String doCfxs() {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("nbzzbm", "1111111111111");
		params.put("doctorAcct", "987654321");
		params.put("doctorName", "王刘");
		params.put("custName", "顾客姓名");
		params.put("custSex", 1);
		params.put("custWeight", 52.2);
		params.put("custAge", 26);
		params.put("custTel", "15888888888");
		params.put("custAddr", "重庆渝中区");
		params.put("startTime", "2018-10-01 09:00:00");
		params.put("endTime", "2018-10-01 09:01:16");
		params.put("costTime", 76);
		params.put("rxData", JSONFile.loadFiles(FileBasePath, "id-1.jpg"));
		params.put("voiceData", JSONFile.loadFiles(FileBasePath, "1.mp3"));
		params.put("videoData", JSONFile.loadFiles(FileBasePath, "2.mp4"));
		params.put("rxCode", "cf001");
		params.put("auditPharName", "刘刘");
		params.put("auditPharStatus", 1);
		params.put("auditPharTime", "2018-10-01 10:00:00");
		prpareOrgInfo(params);
		return this.httpClient.postJSON(urlMapping.get(UrlKey.upload_xscf), params);
	}
	
	
	public String doDevice() {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("nbzzbm", "1111111111111");
		params.put("deviceCode", "987654321");
		params.put("deviceName", "设备名称");
		params.put("deviceStatus", 1);
		params.put("deviceStatusTime", "2018-10-01 08:00:00");
		params.put("regTime", "2018-10-01 13:00:20");
		params.put("heartTime", "2018-10-01 13:00:20");
		params.put("teamId", "9527");
		params.put("softwareVersion", "v.1.1");

		prpareOrgInfo(params);
		return this.httpClient.postJSON(urlMapping.get(UrlKey.upload_device), params);
	}
	
	/**
	 * 医生
	 * @return
	 */
	public String doUploadDoctor() {
		Map<String, Object> params = new HashMap<String, Object>();
		//params.put("nbzzbm", "500232198707081518");//所属药店内部标识
		params.put("acct", "wangchuan");//账号
		params.put("name", "wangchuan");//姓名
		params.put("sex", "1");//性别 1-男,2-女
		params.put("nation", "汉");//民族
		params.put("education", "大学");//学历
		params.put(" major", "解剖学");//专业
		params.put("positionalTitle", "医生");//职称
		params.put("photoFile", JSONFile.loadFiles(FileBasePath, "photo-1.jpg", "photo-2.jpg", "photo-3.jpg"));//照片文件
		params.put("idCode", "500232198707081518");//身份证号
		params.put("idFile", JSONFile.loadFiles(FileBasePath, "id-1.jpg", "id-2.jpg"));//身份证文件
		params.put("pecCode", "500232198707081518");//职业资格证书号
		params.put("pecFile", JSONFile.loadFiles(FileBasePath, "pec-1.jpg"));//职业资格证书文件
		params.put("graduatedFrom", "cyAdmin");//毕业学校
		params.put("typeOfJob", "cyAdmin");//类别
		params.put("post", "cyAdmin");//工作岗位
		params.put("tel", "cyAdmin");//本人联系电话
		params.put("deptName", "cyAdmin");//所属科室
		params.put("resume", "cyAdmin");//个人简介
		params.put("goodAt", "cyAdmin");//擅长领域
		params.put("remark", "cyAdmin");//备注信息
		params.put("userStatus", 1);//人员状态
		prpareOrgInfo(params);
		return this.httpClient.postJSON(urlMapping.get(UrlKey.upload_doctor), params);
	}

	public String doLogin() throws Exception {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("tj_randomkey", captchaKey());
		params.put("tj_username", Base64Utils.encode("900000000000007".getBytes()));
		params.put("tj_password", DigestUtils.md5Hex("900000000000007"));
		params.put("json", "true");
		return this.httpClient.post(urlMapping.get(UrlKey.auth_doLogin), params);
	}

	public static void main(String[] arg) throws Exception {
		YzqHttpUrlClient client = new YzqHttpUrlClient();
		System.out.println(client.doLogin());
		System.out.println(client.doUploadDoctor());
//		System.out.println(client.doUploadYsxx());
//		System.out.println(client.doYskq());
//		System.out.println(client.doDevice());
	}

}
